﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.WebControls;
using SaleDiscount.Portal.Common;
using SaleDiscount.Portal.eBay;
using eBay.Service.Core.Sdk;

namespace SaleDiscount.Portal
{
    public partial class TokenEdit : SaleDiscountPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CancelButton = btnCancel;

            }
        }
        protected void btnActive_Click(object sender, EventArgs e)
        {
          
            if (Session["sessionId"] != null && !string.IsNullOrEmpty(Session["sessionId"].ToString()) &&
        !string.IsNullOrWhiteSpace(EbayUserName))
            {
                ApiContext context = eBaySession.LoadEmptyApiContext(EbayUserName);

                //FetchToken
                var entity =
                    (eBaySession.ActivateUser(context, Session["sessionId"].ToString(), EbayUserName, EbayUserTokenId));
                if(!string.IsNullOrWhiteSpace(entity.Token))
                {
                    Status = "Active";
                    EbayUserTokenId = entity.Id;
                    eBaySession.LoadApiContext(entity.Token, EbayUserName);
                }
              
            }
            CloseWindow(true);
        }
    }
}